package com.live.stamp.base.validation;

/**
 * 参数验证（责任链模式）
 */
public abstract class ParamHandler {

    private ParamHandler nextHandle;

    public final ParamHandler handleMessage(String paramName, Object param, ValidationEnum paramType){
        if(this.getParamHandleType().equals(paramType)){
            this.echo(paramName, param);
        }else {
            if(this.nextHandle != null){
                this.nextHandle.handleMessage(paramName, param, paramType);
            }
        }
        return this;
    }

    public void setNext(ParamHandler handler){
        this.nextHandle = handler;
    }

    protected abstract ValidationEnum getParamHandleType();
    //处理任务
    protected abstract void echo(String paramName, Object param);
}
